package com.mmdccj.yugu.mapper;

import com.mmdccj.yugu.dto.CommentDto;
import com.mmdccj.yugu.dto.PostDto;
import com.mmdccj.yugu.entity.Post;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: star_
 * @date: 2023-11-30 18:46
 */
@Mapper
public interface PostMapper {

    // 创建动态
    @Insert("insert into post (id, content, likes, share_count, create_time, user_id) values (#{id}, #{content}, 0, 0, #{createTime}, #{userId})")
    void insertPost(Post post);

    // 插入图片
    void insertPostImage(Post post);


    //获取全部动态
    List<PostDto> selectAllPost();


    @Select("SELECT comment_count FROM user_post WHERE id = #{postId}")
    Integer selectCommentCount(String postId);

    @Select("SELECT COUNT(*) FROM user_like_post WHERE post_id=#{postId} AND user_Id=#{userId}")
    int checkLike(String userId, String postId);

    @Select("SELECT likes FROM post WHERE id=#{postId}")
    Integer like(String postId);

    @Update("UPDATE post SET likes=#{likes} WHERE id=#{postId}")
    void updateLike(String postId, int likes);

    /**
     * 更新点赞表数据
     *
     * @param postId postId
     * @param userId userId
     */
    @Insert("INSERT INTO user_like_post(user_id,post_id) VALUES(#{userId},#{postId})")
    void insertLikeTo(String postId, String userId);

    @Select("SELECT * from user_post where id = #{postId}")
    PostDto selectOne(String postId);

    List<PostDto> selectAllMyPost(String userId);
}
